<template>
  <div class="list">
        <el-table
        :data="bill"
        style="width: 100%">
        <el-table-column
        prop="customerId"
        label="用户id"
        width="">
        </el-table-column>
        <el-table-column
        prop="roomId"
        label="房间id"
        width="">
        </el-table-column>
        <el-table-column
        prop="money"
        label="金额">
        </el-table-column>
        <el-table-column
        label="订单状态">
          <template slot-scope="scope">
            <el-tag :type="scope.row.endTime == null ? 'info' : 'success'">{{ scope.row.endTime !== null ? '已完成' : '未完成' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
        prop="phone"
        label="顾客手机号">
        </el-table-column>
        <el-table-column
        prop="createTime"
        label="账单生成时间">
        </el-table-column>
        <el-table-column
        prop="endTime"
        label="退房时间">
        </el-table-column>
        <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button type="text" :disabled="scope.row.endTime == null ? true : false" size="small" @click="cancelBill(scope.row.id)">删除账单</el-button>
      </template>
    </el-table-column>
       
        </el-table>
        <div class="pager">
           <el-pagination
        background
        layout="prev, pager, next,total"
        :total="total"
        :page-size="pageData.pageSize"
        @current-change="handlePage">
        </el-pagination>
        </div>
       

    </div>
</template>

<script>
import {billPage, delBill} from '@/api/bill'
export default {
  name:'',
  components: {  },
  data() {
      return {
          bill:[],
          pageData:{
            page:1,
            pageSize:12,
          },
          total:0,
      }
  },
  methods:{
    cancelBill(id){
      delBill({params:{id}}).then(res =>{
        let {data,msg,code} = res.data
        if(code ===1){
          this.$message.success(data)
          this.getList()
        }else{
          this.$message.error(msg)
        }
      }).catch(err =>{
        this.$message.error('后端出现异常',err)
      })
    },
    handlePage(val){
        this.pageData.page = val
        this.getList()
    },
    getList(){
      billPage({params:this.pageData}).then(res =>{
        // console.log('很要命--bill展示-----',res);
        let {data,code,msg} = res.data
        if(code === 1){
          this.bill = data.records
          this.total = Number(data.total)
        }else{
          if(msg != null){
            this.$message.error(msg)
          }else{this.$message.error('获取数据失败')}
        }
      }).catch(err=>{
        this.$message.error('连接服务器失败',err)
      })
    },
  },
  mounted(){
      this.getList()
  }
}
</script>

<style lang="less" scoped>

.pager{
    position: absolute;
    bottom: 30px;
    // right: 20px;
    left: 50%;
  }
</style>